package com.ztjava.portal;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.ztjava.core.Constant;
import com.ztjava.core.HPlugin;
import com.ztjava.portal.controller.PortalController;
import com.ztjava.portal.model.PortalParam;
import com.ztjava.portal.model.PortalRole;
import com.ztjava.portal.model.PortalUser;
import com.ztjava.portal.model.PortalUserRole;

public class Portal extends HPlugin{
	@Override
	public void configConstant(Constants me) {
		Constant.BackPlugin = "Portal";
	}
	@Override
	public void configRoute(Routes me) {
		me.add("/portal",PortalController.class);
	}

	@Override
	public void configArp(ActiveRecordPlugin arp) {
		addMapping(arp, PortalUser.tablename, PortalUser.class);
		addMapping(arp, PortalRole.tablename, PortalRole.class);
		addMapping(arp, PortalParam.tablename, PortalParam.class);
		addMapping(arp, PortalUserRole.tablename,PortalUserRole.class);
	}

	@Override
	public void configInterceptor(Interceptors me) {
	}

	@Override
	public void configHandler(Handlers me) {
		
	}

	@Override
	public void afterJFinalStart() {
		PortalParam.loadCache();
		PortalUser.loadUserFullnameCache();
		
		PortalUser portalUser = PortalUser.dao.findFirst("select * from "+PortalUser.tablename+" where username='admin'");
		if(portalUser==null){
			portalUser = new PortalUser();
			portalUser.set("username", "admin");
			portalUser.set("password", "C4CA4238A0B923820DCC509A6F75849B");
			portalUser.set("email", "ztwindbell@qq.com");
			portalUser.set("fullname", "管理员");
			portalUser.save();
		}
	}


}
